﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Glimpse.Core.Framework;
using Orchard.Mvc;
using Glimpse.Core.Extensions;

namespace Glimpse.Controllers
{
    public class AssetController : Controller
    {
        private readonly IHttpContextAccessor _hca;


        public AssetController(IHttpContextAccessor hca)
        {
            _hca = hca;
        }
	
			
        public void Index([Bind(Prefix = "n")] string resourceName)
        {
            var httpContext = _hca.Current();

            // HACK: This is a hack for the POC. We will update Glimpse to allow for calling GlimpseRuntime.Instance instead.
            var glimpseRuntime = httpContext.Application["__GlimpseRuntime"] as GlimpseRuntime;

            if (string.IsNullOrEmpty(resourceName))
                glimpseRuntime.ExecuteDefaultResource();
            else
                glimpseRuntime.ExecuteResource(resourceName, new ResourceParameters(httpContext.Request.QueryString.ToDictionary()));
        }
    }
}